<?php

require( realpath('..') . '/includes/admin.php' );

auth();
$dora->database();

if( action('update') ) {
	extract($_POST);
	
	if( isset($_FILES['picture']) ) {
		$file_name = $_FILES['picture']['name'];
		$extend = pathinfo( $file_name ); 
		$extend = strtolower($extend["extension"]);
		$new_file_name = rand(1,100000) . "." . $extend;
		$picture_path = 'uploads/' . $new_file_name;
	
		if(@move_uploaded_file($_FILES['picture']['tmp_name'], '../' . $picture_path)) {
		
		}
		else {
			$dora->lib('message');
			$dora->message->set('房源图片上传失败');
			$dora->view('house_fo');
			exit;
		}
		$sql = "update house set name='$name', picture_path='$picture_path', content='$content' where id=$id";
	}
	else {
		$sql = "update house set name='$name', content='$content' where id=$id";	
	}
	
	$dora->db->query($sql);
	
	$dora->lib('message');
	$dora->message->set('修改文章成功');
	
	$dora->view('article_fo');
}
else {
	$id = $_GET['id'];
	$house = $dora->db->get_result('select * from house where id=' . $id);
	$dora->set('house', $house);
	
	$dora->view('house_update');
}

?>